<template>
  <v-app>
    <v-progress-linear
        :active="pageLoading"
        :indeterminate="pageLoading"
        color="deep-purple accent-4"
        absolute>
    </v-progress-linear>
    <transition name="scroll-x-reverse-transition" mode="out-in" appear>
      <router-view></router-view>
    </transition>
  </v-app>
</template>

<script>
import Ws from '@/utils/ws'
import { mapGetters } from 'vuex'

export default {
  name: 'App',
  data: () => ({
    links: [
      'Dashboard',
      'Messages',
      'Profile',
      'Updates'
    ],
    to: [
      '/',
      '/home',
      '/about',
      '/1',
      '/2'
    ]
  }),
  created() {
    const url = process.env['VUE_APP_WS_URL']
    let ws = new Ws({
      url,
      maxReConTimes: 8,
      channels: [
        {
          channel: 'tips',
          handler: (data) => {
            console.log(data)
          }
        }
      ]
    })
    Ws.add_channel('system', data => {
      let { mem, cpu } = data
      mem = mem.map(e => JSON.parse(e))
      cpu = cpu.map(e => JSON.parse(e))
      this.$store.dispatch('system', { mem, cpu })
    })
  },
  computed: {
    ...mapGetters(['pageLoading'])
  }
}
</script>
